package com.dandev.cmdemo.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.dandev.cmdemo.form.Contact;
import com.dandev.cmdemo.service.ContactService;

/**
 * Controller for /index, list a tree of contacts
 * 
 * @author Dan
 */
@Controller
@RequestMapping("/index")
public class IndexController {
	
	@Autowired
    private ContactService contactService;
	
	/**
	 * Handles an /index get request.
	 * @param model request data
	 * @return view name
	 */
	@RequestMapping(method=RequestMethod.GET)
	public String index(Model model) {
		Contact rootContact = new Contact();
		rootContact.setContactList(contactService.listContact());
		model.addAttribute("contact", rootContact);
		
		return "index";
	}
	
}
